/**
* @file   DsCopy.cpp
* @brief  Implementation file for class DsCopy
* @date   2011-04-12 20:31:17
* @author Yanze Lian
* @email  <yanzel@gmail.com>
*/

#include "stdafx.h"
#include "DsCopy.h"
#include "safe_defs.h"
#include "FileWriter.h"
#include "DxFuncs.h"


DsCopy::DsCopy()
{
	m_pGraph = NULL;
}

DsCopy::~DsCopy()
{
}

HRESULT DsCopy::Init()
{
	UnInit();
	HRESULT hr = S_OK;
	do 
	{
		hr = DxFuncs::CreateFilterGraph(&m_pGraph);
	} while (false);
	if(FAILED(hr))
		UnInit();
	return hr;
}

void DsCopy::UnInit()
{
	SAFE_RELEASE(m_pGraph);
}

bool DsCopy::Convert(CString sourceFile, CString targetFile)
{
	HRESULT hr = S_OK;

	do 
	{
		hr = Init();
		BREAK_IF_FAILED(hr, _T("DsCopy Convert Init"));

		FileWriter fileWriter;
		hr = fileWriter.Init(m_pGraph, targetFile);
		BREAK_IF_FAILED(hr, _T("DsCopy fileWriter"));

		fileWriter.UnInit();

	} while (false);

	UnInit();
	return SUCCEEDED(hr);
}


